//
//  UILabel+AdjustFont.m
//  可旋转放大缩小的图片
//
//  Created by Mars_ZXB on 16/7/18.
//  Copyright © 2016年 BAT3. All rights reserved.
//

#import "UILabel+AdjustFont.h"

@implementation UILabel (AdjustFont)

- (void)adjustFont{
    for (int i = 100; i >= 16; i --) {
        UIFont *font = [UIFont fontWithName:self.font.fontName size:i];
        CGRect rectSize = [self.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, font.lineHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : font}  context:nil];
        if (rectSize.size.width <= self.frame.size.width) {
            self.font = [UIFont fontWithName:self.font.fontName size:i];
            break;
        }
    }
}
@end
